package com.dearbinge.data.service.impl.life;

import com.baomidou.mybatisplus.plugins.Page;
import com.dearbinge.data.api.life.LifeMessageService;
import com.dearbinge.data.api.moments.BusinessCircleCommentService;
import com.dearbinge.data.dao.ThumbsMapper;
import com.dearbinge.data.dao.UserMapper;
import com.dearbinge.data.dao.moments.BusinessCircleMapper;
import com.dearbinge.data.dao.moments.LifeMessageMapper;
import com.dearbinge.data.pojo.life.LifeMessage;
import com.dearbinge.data.pojo.life.vo.LifeMessageVO;
import com.dearbinge.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 生活信息 业务层实现层
 *
 * @author wes
 * @date 2019/1/9
 */
@Service("lifeMessageService")
public class LifeMessageServiceImpl implements LifeMessageService {

    @Autowired
    private LifeMessageMapper lifeMessageMapper;
    @Autowired
    private BusinessCircleMapper businessCircleMapper;
    @Autowired
    private ThumbsMapper thumbsMapper;
    @Autowired
    private BusinessCircleCommentService businessCircleCommentService;
    @Autowired
    private UserMapper userMapper;
    /**
     * 生活信息 增加
     * @param lifeMessage 生活信息
     * @return 结果提示
     */
    @Override
    public Integer insertLifeMessage(LifeMessage lifeMessage) {
        //插件生活表
        Integer insertLife = lifeMessageMapper.insertLifeMessage(lifeMessage);
        //插件社交圈表
        Integer insertCircle =  businessCircleMapper.insertLifeMessage(lifeMessage);
        return insertLife+insertCircle;
    }

    /**
     * 修改生活信息
     * @param lifeMessage 生活信息
     * @return 成功提示
     */
    @Override
    public Integer updateLifeMessage(LifeMessage lifeMessage) {
        //修改生活圈信息
        Integer updateLife = lifeMessageMapper.updateLifeMessage(lifeMessage);
        //修改社交圈信息
        Integer updateCircle = businessCircleMapper.updateLifeMessage(lifeMessage);
        return updateLife+updateCircle;
    }





    /**
     * 查询一个用户发布的生活信息
     *
     * @param userId  用户id
     * @param current 当前页
     * @param size    每页展示条数
     * @return 分页结果
     */
    @Override
    public Page listLiveMoments(String userId, Integer current, Integer size) {
        current = PageUtils.getDefaultValues(current, 1);
        size = PageUtils.getDefaultValues(size, 10);
        //分页
        Page<LifeMessageVO> page = new Page<>(current, size);
        List<LifeMessageVO> list = lifeMessageMapper.listMyLive(userId, page);
        //查出总条数
        Long count = lifeMessageMapper.countMyLive(userId);
        //最大数
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }


    //    /**
//     * 删除生活信息动态
//     * @param id 主键id
//     * @return 结果
//     */
//    @Override
//    public Integer deleteLifeMessageById(Integer id) {
//        //删除生活信息表
//        Integer deleteLife = lifeMessageMapper.deleteLifeMessageById(id);
//        //删除社交圈表
//        Integer deleteCircle = businessCircleMapper.deleteBusinessCircle(TypeCodeEnum.BUSINESS_CIRCLE_LIFE.getCode(),id);
//        return deleteLife+deleteCircle;
//    }



}
